<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('稿件管理列表')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>稿件类型：</label>
                            <select name="paperType" th:with="type=${@dict.getType('work_paper_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>是否销账：</label>
                            <select name="isCancel" th:with="type=${@dict.getType('work_cancel_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>是否请款：</label>
                            <select name="requestStatus" th:with="type=${@dict.getType('work_request_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>稿件名称：</label>
                            <input type="text" name="paperName"/>
                        </li>
                        <li>
                            <label>稿件所属：</label>
                            <input type="text" name="belong"/>
                        </li>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="customerName"/>
                        </li>
                        <li>
                            <label>客户公司：</label>
                            <input type="text" name="companyName"/>
                        </li>
                        <li>
                            <label>媒体名称：</label>
                            <input type="text" name="mediaName"/>
                        </li>
                        <li>
                            <label>媒介：</label>
                            <input type="text" name="mediaCreate"/>
                        </li>
                        <li>
                            <label>联系人：</label>
                            <input type="text" name="contacts"/>
                        </li>

                        <li>
                            <label>平台：</label>
                            <select class="form-control" name="platform"
                                    th:with="type=${@dict.getType('work_platform')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="paperStatus" th:with="type=${@dict.getType('work_paper_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>是否开票：</label>
                            <select name="isInvoice" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>登记时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li class="select-time">
                            <label>刊登时间： </label>
                            <input type="text" class="time-input" id="startTime1" placeholder="开始时间"
                                   name="params[pbbeginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime1" placeholder="结束时间"
                                   name="params[pbendTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>

        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="work:paper:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="work:paper:edit">
                                <i class="fa fa-edit"></i> 修改
                            </a>-->
            <a class="btn btn-success multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="work:paper:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="$.table.importExcel()" shiro:hasPermission="work:paper:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-success" onclick="$.table.exportExcel()" shiro:hasPermission="work:paper:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-success" onclick="setCustomer()" shiro:hasPermission="work:paper:setcustomer">
                <i class="fa "></i> 批量设置客户
            </a>
            <a class="btn btn-success" onclick="changeP()" shiro:hasPermission="work:paper:changeprice">
                <i class="fa "></i> 批量改价
            </a>
            <a class="btn btn-success" onclick="setmedia()" shiro:hasPermission="work:paper:setmedia">
                <i class="fa "></i> 批量领取
            </a>
            <a class="btn btn-success" onclick="fund()" shiro:hasPermission="work:paper:fund">
                <i class="fa "></i> 请款
            </a>
<!--            <a class="btn btn-success" onclick="publish()" shiro:hasPermission="work:paper:publish">
                <i class="fa "></i> 刊登
            </a>-->
            <button  class="btn btn-success" data-toggle="modal" onclick="publishcheck()"  shiro:hasPermission="work:paper:publish">刊登</button>
            <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header" style="padding: 10px 15px">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label>刊登地址</label>
                                <input type="text" placeholder="" class="form-control" name="publishLink" id="publishLink">
                            </div>
                            <div class="form-group">
                                <label>刊登时间</label>
                                <div class="input-group date">
                                    <input name="publishDate" id="publishDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>

                                </div>
                            </div>
                         </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" onclick="publish()">保存</button>
                        </div>
                    </div>
                </div>
            </div>

            <a class="btn btn-success" onclick="reject()" shiro:hasPermission="work:paper:reject">
                <i class="fa "></i> 批量拒稿
            </a>
            <a class="btn btn-success" onclick="process()" shiro:hasPermission="work:paper:process">
                <i class="fa "></i> 批量处理
            </a>
            <a class="btn btn-success" onclick="undo()" shiro:hasPermission="work:paper:undo">
                <i class="fa "></i> 取消处理
            </a>
            <a class="btn btn-success" onclick="publish2()" shiro:hasPermission="work:paper:publish">
                <i class="fa "></i> 批量刊登
            </a>
        </div>

        <div class="col-sm-12">
            <div class="tabs-container">
                <ul id="myTab" class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">普通稿件</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">项目稿件</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body">

                            <div class="select-table table-striped">
                                <table id="bootstrap-table" class="table text-nowrap"></table>
                            </div>

                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>
    <th:block th:include="include :: footer"/>
    <th:block th:include="include :: select2-js"/>
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-select-js"/>
    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('work:paper:add')}]];
        var editFlag = [[${@permission.hasPermi('work:paper:edit')}]];
        var publishFlag = [[${@permission.hasPermi('work:paper:publish')}]];

        var removeFlag = [[${@permission.hasPermi('work:paper:remove')}]];
        var paperTypeDatas = [[${@dict.getType('work_paper_type')}]];
        var platformDatas = [[${@dict.getType('work_platform')}]];
        var priceTypeDatas = [[${@dict.getType('work_price_type')}]];
        var paperStatusDatas = [[${@dict.getType('work_paper_status')}]];
        var prefix = ctx + "work/paper";
        var path = window.location.pathname.split("/")[2].toLowerCase()

        var paperType = {
            netpaper: "1",
            wbpaper: "2",
            wxpaper: "3",
            planepaper: "4",
            apppaper: "5",
            flowpaper: "6"
        };
        var url = paperType[path];
        var options = {};

        function setHeight() {
            //设置bootstrapTable起始的高度

            $('#bootstrap-table').bootstrapTable({height: 120});
            //当表格内容的高度小于外面容器的高度，容器的高度设置为内容的高度，相反时容器设置为窗口的高度-160
            /*            if ($(".fixed-table-body table").height() < $(".fixed-table-container").height()) {
                            $(".fixed-table-container").css({ "padding-bottom": "0px", height: $(".fixed-table-body table").height() + 20 });
                            // 是当内容少时，使用搜索功能高度保持不变
                            $('#bootstrap-table').bootstrapTable('resetView', { height: "auto" });
                        } else {
                            $(".fixed-table-container").css({ height: $(window).height() - 160 });
                        }*/

        };
        $("input[name='publishDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function () {


            if (addFlag == "") {//没有发布稿件的权限，业务员，不是媒介
                paper();
            } else if (publishFlag == "") {

                mediaPaper();
            }
            $.table.destroy('bootstrap-table');
            $.table.init(options);


            $("#myTab a").click(function (e) {
                e.preventDefault();
                var tab = $(this).attr("href");
                if (tab == "#tab-1") {

                    if (addFlag == "") {//没有发布稿件的权限，业务员，不是媒介
                        paper();
                    } else if (publishFlag == "") {

                        mediaPaper();
                    }
                    $.table.destroy('bootstrap-table');
                    $.table.init(options);

                } else {
                    if (addFlag == "") {//没有发布稿件的权限，业务员，不是媒介
                        paperGroup();
                    } else if (publishFlag == "") {

                        mediaGroup();
                    }
                    $.table.destroy('bootstrap-table');
                    $.table.init(options);
                }
            });


        });

        function paper() {
            options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "稿件管理",
                showFooter: true,
                sortName: 'paper_id',
                sortOrder: "desc",
                footerStyle: footerStyle,
                pageSize: 500,
                pageNumber: 1,
                pageList: [500, 1000, 1500],
                height: $(window).height() - 300,
                striped: true,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        width: 80,
                        footerFormatter: function (value) {
                            return "合计：";
                        }
                    },
                    {
                        field: 'paperStatus',
                        title: '状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperStatusDatas, value);
                        },
                        width: 100
                    },
                    {
                        field: 'paperType',
                        title: '稿件类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperTypeDatas, value);
                        },
                        width: 100

                    },
                    {
                        field: 'paperName',
                        title: '稿件名称',
                        colspan: 1,
                        width: 500,
                        widthUnit: 'px'

                    },
                    {
                        field: 'uploadFile',
                        title: '上传稿件',
                        formatter: function (value, row, index) {
                            if (value != '' && value != undefined) {
                                var fileName = value.substr(value.lastIndexOf("/") + 1);
                                return '<a  href="' + ctx + "common/download/resource?resource=" + value + '" target="_blank">' + fileName + '</a>';

                            } else {
                                return value
                            }
                        },
                        width: 200
                    },
                    {
                        field: 'belong',
                        title: '稿件所属',
                        width: 80
                    },

                    {
                        field: 'customerName',
                        title: '客户名称',
                        width: 200

                    },
                    {
                        field: 'companyName',
                        title: '客户所属公司',
                        width: 200

                    }, {
                        field: 'createTime',
                        title: '登记时间',
                        width: 200
                    },
                    {
                        field: 'mediaName',
                        title: '媒体名称',
                        formatter: function (value, row, index) {
                            return '<a  href="javascript:void(0)" onclick="viewMedia(\'' + row.paperType + '\',\'' + row.mediaId + '\')">' + value + '</a>';
                        },
                        width: 200
                    },
                    {
                        field: 'platform',
                        title: '平台',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(platformDatas, value);
                        },
                        width: 100

                    },
                    {
                        field: 'mediaCreate',
                        title: '媒介',
                        width: 200

                    },
                    {
                        field: 'publishLink',
                        title: '刊登链接',
                        width: 200

                    },
                    {
                        field: 'publishDate',
                        title: '刊登时间',
                        width: 100,
                    },
                    {
                        field: 'paperPrice',
                        title: '稿件费',
                        width: 100,
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].paperPrice);
                            }
                            return sumBalance;
                        }
                    },
                    {
                        field: 'flowPrice',
                        title: '刷量费',
                        width: 100

                    },
                    {
                        field: 'cost',
                        title: '成本',
                        width: 100,
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].cost);
                            }
                            return sumBalance;
                        }
                    },
                    {
                        field: 'actualCost',
                        title: '实际成本',
                        width: 100,
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualCost);
                            }
                            return sumBalance;
                        }
                    },
                    {
                        field: 'price',
                        title: '单价',
                        width: 100
                    },
                    {
                        field: 'words',
                        title: '字数',
                        width: 100
                    },
                    {
                        field: 'actualPrice',
                        title: '实际总价',
                        width: 100,
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualPrice);
                            }
                            return sumBalance;
                        }
                    },
                    {
                        field: 'priceType',
                        title: '价格类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(priceTypeDatas, value);
                        },
                        width: 100
                    },
                    {
                        field: 'offAccountDate',
                        title: '销账时间',
                        width: 100
                    },
                    {
                        field: 'commision',
                        title: '提成',
                        width: 100
                    },
                    {
                        field: 'commisionDate',
                        title: '提成时间',
                        width: 100
                    },
                    {
                        field: 'flowRemark',
                        title: '刷量备注',
                        width: 200
                    },
                    {
                        field: 'originalLink',
                        title: '原始链接',
                        width: 200
                    },
                    {
                        field: 'paybackPeriod',
                        title: '回款周期',
                        width: 100
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        width: 200
                    }]
            };
        }

        function paperGroup() {
            options = {
                url: prefix + "/grouplist",
                exportUrl: prefix + "/groupexport",
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "稿件管理",
                showFooter: true,
                sortName: 'paper_id',
                sortOrder: "desc",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                detailView: true,
                pageSize: 500,
                pageNumber: 1,
                pageList: [500, 1000, 1500],
                height: $(window).height() - 300,

                onExpandRow: function (index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        width: 100
                    }, {
                        field: 'batchId',
                        title: 'batchId',
                        visible: false
                    }, {
                        field: 'paperName',
                        title: '稿件名称'

                    }]
            };
        }

        function mediaGroup() {
            options = {
                url: prefix + "/grouplist/" + url,
                exportUrl: prefix + "/mediagroupexport/" + url,
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "稿件管理",
                showFooter: true,
                sortName: 'paper_id',
                sortOrder: "desc",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                detailView: true,
                onExpandRow: function (index, row, $detail) {
                    mediaChildTable(index, row, $detail);
                },
                columns: [
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        width: 100
                    }, {
                        field: 'batchId',
                        title: 'batchId',
                        visible: false
                    }, {
                        field: 'paperName',
                        title: '稿件名称'

                    }]
            };
        }

        function mediaPaper() {
            options = {
                url: prefix + "/list/" + url,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/mediaexport/" + url,
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "稿件管理",
                sortName: 'paper_id',
                sortOrder: "desc",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                showFooter: true,
                footerStyle: footerStyle,
                striped: true,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        footerFormatter: function (value) {
                            return "合计：";
                        }
                    },
                    {
                        field: 'publishDate',
                        title: '刊登时间'
                    },
                    {
                        field: 'paperStatus',
                        title: '状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperStatusDatas, value);
                        }
                    },

                    {
                        field: 'paperName',
                        title: '稿件名称'

                    }, {
                        field: 'platform',
                        title: '平台',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(platformDatas, value);
                        }

                    },
                    {
                        field: 'uploadFile',
                        title: '上传稿件',
                        formatter: function (value, row, index) {
                            if (value != '' && value != undefined) {
                                var fileName = value.substr(value.lastIndexOf("/") + 1);
                                return '<a  href="' + ctx + "common/download/resource?resource=" + value + '" target="_blank">' + fileName + '</a>';

                            } else {
                                return value
                            }

                        }
                    },
                    {
                        field: 'mediaName',
                        title: '媒体名称',
                        formatter: function (value, row, index) {
                            return '<a  href="javascript:void(0)" onclick="viewMedia(\'' + row.paperType + '\',\'' + row.mediaId + '\')">' + value + '</a>';
                        }
                    },
                    {
                        field: 'paperType',
                        title: '稿件类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperTypeDatas, value);
                        }

                    }, {
                        field: 'requestId',
                        title: '请款',
                        formatter: function (value, row, index) {

                            if (CheckIsNullOrEmpty(value)) {
                                var actions = [];
                                actions.push('<a  href="javascript:void(0)" onclick="viewFund(\'' + value + '\')">请款信息</a> ');
                                return actions.join('');
                            } else {
                                return '未请款'
                            }

                        }

                    }, {
                        field: 'contacts',
                        title: '联系人'
                    }, {
                        field: 'mediaCreate',
                        title: '安排媒介'
                    },
                    {
                        field: 'actualCost',
                        title: '价格',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualCost);
                            }
                            return sumBalance;
                        }
                    },

                    {
                        field: 'payTime',
                        title: '支付时间'
                    },
                    {
                        field: 'belong',
                        title: '稿件所属'
                    },
                    {
                        field: 'createTime',
                        title: '录入时间'
                    },
                    {
                        field: 'publishLink',
                        title: '刊登链接'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    }]
            };
        }

        var arr = [];
        initChildTable = function (index, row, $detail) {
            var childTable = $detail.html('<table class="table text-nowrap"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/list",
                /*   createUrl: prefix + "/add",
                   updateUrl: prefix + "/edit/{id}",
                   removeUrl: prefix + "/remove",
                   exportUrl: prefix + "/export",
                   importTemplateUrl: prefix + "/importTemplate",
                   importUrl: prefix + "/importData",*/
                modalName: "稿件管理",
                showFooter: true,
                footerStyle: footerStyle,
                striped: true,
                id: 'child-table',
                sortName: 'paper_id',
                sortOrder: "desc",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    batchId: row.batchId
                },
                onCheck: function (on) {
                    arr.push(on.paperId);
                },               // 当选择此行时触发
                onUncheck: function (off) {
                    var i = arr.indexOf(off.paperId);
                    if (i >= 0) {
                        arr.splice(i, 1);
                    }
                },
                onCheckAll: function (all) {
                    $.each(all, function (index, value) {
                        arr.push(value.paperId);
                    })

                },     // 当全选行时触发
                onUncheckAll: function () {
                    arr = [];
                },
                columns: [{
                    checkbox: true,
                    formatter: function (value, row, index) {

                        if (row.isCheck > 0) { //根据行里字段判断是否选中
                            arr.push(row.paperId)
                            return {
                                checked: true//设置选中
                            };
                        }
                        return value;
                    }
                },
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        align: 'center',
                        footerFormatter: function (value) {
                            return "合计：";
                        }
                    },
                    {
                        field: 'paperStatus',
                        title: '状态',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperStatusDatas, value);
                        }

                    },
                    {
                        field: 'paperType',
                        title: '稿件类型',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperTypeDatas, value);
                        }

                    },
                    {
                        field: 'paperName',
                        title: '稿件名称',
                        align: 'center'

                    },
                    {
                        field: 'uploadFile',
                        title: '上传稿件',
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value != '' && value != undefined) {
                                var fileName = value.substr(value.lastIndexOf("/") + 1);
                                return '<a  href="' + ctx + "common/download/resource?resource=" + value + '" target="_blank">' + fileName + '</a>';

                            } else {
                                return value
                            }
                        }
                    },
                    {
                        field: 'belong',
                        title: '稿件所属',
                        align: 'center'
                    },

                    {
                        field: 'customerName',
                        title: '客户名称',
                        align: 'center'

                    },
                    {
                        field: 'companyName',
                        title: '客户所属公司',
                        align: 'center'

                    }, {
                        field: 'createTime',
                        title: '登记时间',
                        align: 'center'
                    },
                    {
                        field: 'mediaName',
                        title: '媒体名称',

                        formatter: function (value, row, index) {
                            return '<a  href="javascript:void(0)" onclick="viewMedia(\'' + row.paperType + '\',\'' + row.mediaId + '\')">' + value + '</a>';
                        },
                        align: 'center'
                    },
                    {
                        field: 'mediaCreate',
                        title: '媒介',
                        align: 'center'

                    },
                    {
                        field: 'publishLink',
                        title: '刊登链接',
                        align: 'center'

                    },
                    {
                        field: 'platform',
                        title: '平台',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(platformDatas, value);
                        },
                        align: 'center'

                    },

                    {
                        field: 'publishDate',
                        title: '刊登时间',
                        align: 'center'
                    },
                    {
                        field: 'paperPrice',
                        title: '稿件费',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].paperPrice);
                            }
                            return sumBalance;
                        },
                        align: 'center'
                    },
                    {
                        field: 'flowPrice',
                        title: '刷量费',
                        align: 'center'

                    },
                    {
                        field: 'cost',
                        title: '成本',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].cost);
                            }
                            return sumBalance;
                        },
                        align: 'center'
                    },
                    {
                        field: 'actualCost',
                        title: '实际成本',

                        align: 'center',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualCost);
                            }
                            return sumBalance;
                        }
                    },
                    {
                        field: 'price',
                        title: '单价',
                        align: 'center'

                    },
                    {
                        field: 'words',
                        title: '字数',
                        align: 'center'
                    },
                    {
                        field: 'actualPrice',
                        title: '实际总价',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualPrice);
                            }
                            return sumBalance;
                        },
                        align: 'center'
                    },
                    {
                        field: 'priceType',
                        title: '价格类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(priceTypeDatas, value);
                        },
                        align: 'center'
                    },
                    {
                        field: 'offAccountDate',
                        title: '销账时间',
                        align: 'center'
                    },
                    {
                        field: 'commision',
                        title: '提成',
                        align: 'center'
                    },
                    {
                        field: 'commisionDate',
                        title: '提成时间',
                        align: 'center'
                    },
                    {
                        field: 'flowRemark',
                        title: '刷量备注',
                        align: 'center'
                    },
                    {
                        field: 'originalLink',
                        title: '原始链接',
                        align: 'center'
                    },
                    {
                        field: 'paybackPeriod',
                        title: '回款周期',
                        align: 'center'
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        align: 'center'
                    }]
            });
        };

        mediaChildTable = function (index, row, $detail) {
            var mediaChildTable = $detail.html('<table class="table text-nowrap"></table>').find('table');
            $(mediaChildTable).bootstrapTable({
                url: prefix + "/list/" + url,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "稿件管理",
                showFooter: true,
                footerStyle: footerStyle,
                striped: true,
                id: 'child-table',
                sortName: 'paper_id',
                sortOrder: "desc",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    batchId: row.batchId
                },
                onCheck: function (on) {
                    arr.push(on.paperId);
                },               // 当选择此行时触发
                onUncheck: function (off) {
                    var i = arr.indexOf(off.paperId);
                    if (i >= 0) {
                        arr.splice(i, 1);
                    }
                },
                onCheckAll: function (all) {
                    $.each(all, function (index, value) {
                        arr.push(value.paperId);
                    })

                },     // 当全选行时触发
                onUncheckAll: function () {
                    arr = [];
                },
                columns: [{
                    checkbox: true,
                    formatter: function (value, row, index) {

                        if (row.isCheck > 0) { //根据行里字段判断是否选中
                            arr.push(row.paperId)
                            return {
                                checked: true//设置选中
                            };
                        }
                        return value;
                    }
                },
                    {
                        field: 'paperId',
                        title: '稿件ID',
                        footerFormatter: function (value) {
                            return "合计：";
                        }
                    },
                    {
                        field: 'publishDate',
                        title: '刊登时间'
                    },
                    {
                        field: 'paperStatus',
                        title: '状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperStatusDatas, value);
                        }
                    },

                    {
                        field: 'paperName',
                        title: '稿件名称'

                    }, {
                        field: 'platform',
                        title: '平台',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(platformDatas, value);
                        }

                    },
                    {
                        field: 'uploadFile',
                        title: '上传稿件',
                        formatter: function (value, row, index) {
                            if (value != '' && value != undefined) {
                                var fileName = value.substr(value.lastIndexOf("/") + 1);
                                return '<a  href="' + ctx + "common/download/resource?resource=" + value + '" target="_blank">' + fileName + '</a>';

                            } else {
                                return value
                            }

                        }
                    },
                    {
                        field: 'mediaName',
                        title: '媒体名称',
                        formatter: function (value, row, index) {
                            return '<a  href="javascript:void(0)" onclick="viewMedia(\'' + row.paperType + '\',\'' + row.mediaId + '\')">' + value + '</a>';
                        }
                    },
                    {
                        field: 'paperType',
                        title: '稿件类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(paperTypeDatas, value);
                        }

                    }, {
                        field: 'requestId',
                        title: '请款',
                        formatter: function (value, row, index) {

                            if (CheckIsNullOrEmpty(value)) {
                                var actions = [];
                                actions.push('<a  href="javascript:void(0)" onclick="viewFund(\'' + value + '\')">请款信息</a> ');
                                return actions.join('');
                            } else {
                                return '未请款'
                            }

                        }

                    }, {
                        field: 'contacts',
                        title: '联系人'
                    }, {
                        field: 'mediaCreate',
                        title: '安排媒介'
                    },
                    {
                        field: 'actualCost',
                        title: '价格',
                        footerFormatter: function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                sumBalance += parseFloat(value[i].actualCost);
                            }
                            return sumBalance;
                        }
                    },

                    {
                        field: 'payTime',
                        title: '支付时间'
                    },
                    {
                        field: 'belong',
                        title: '稿件所属'
                    },
                    {
                        field: 'createTime',
                        title: '录入时间'
                    },
                    {
                        field: 'publishLink',
                        title: '刊登链接'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    }]
            });
        };

        //判断数据是否为Null或者undefined或者为空字符串
        function CheckIsNullOrEmpty(value) {
            //正则表达式用于判斷字符串是否全部由空格或换行符组成
            var reg = /^\s*$/
            //返回值为true表示不是空字符串
            return (value != null && value != undefined && !reg.test(value))
        }

        function footerStyle(column) {
            return {
                actualPrice: {
                    css: {color: 'red', 'font-weight': 'normal'}
                },
                actualCost: {
                    css: {color: 'red', 'font-weight': 'normal'}
                }, cost: {
                    css: {color: 'red', 'font-weight': 'normal'}
                }, paperPrice: {
                    css: {color: 'red', 'font-weight': 'normal'}
                },
            }[column.field]
        }

        //批量改价
        function changeP() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录改价");
                return;
            }
            layer.prompt({title: '输入价格，并确认', formType: 0}, function (text, index) {
                layer.close(index);


                $.modal.confirm("确认要批量改价选中的" + ids.length + "条数据吗?", function () {

                    $.post(prefix + "/changeprice", {ids: ids.join(), price: text}, function (result) {

                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess("操作成功！")
                            refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }

                    });
                });
            });
        }

        //领取
        function setmedia() {

            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录领取");
                return;
            }

            $.modal.confirm("确认要批量领取选中的" + ids.length + "条数据吗?", function () {

                $.post(prefix + "/setmedia", {ids: ids.join()}, function (result) {

                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功！")
                        refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }

                });
            });

        }

        //请款
        function fund() {

            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');
            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录请款");
                return;
            }
            var requestId = $.table.selectColumns('requestId');
            if (requestId.length > 0) {
                $.modal.alertWarning("请选择没有请款的记录");
                return;
            }
            var contactId = $.table.selectColumns('contactId');

            if (contactId.length != 1) {
                $.modal.alertWarning("请选择相同联系人的记录请款");
                return;
            }
            $.modal.open("请款", ctx + "work/fund/add/" + ids);
        }

        function submitfund(requestId, msg) {
            if (requestId == 0) {
                $.modal.alertWarning(msg);
                return;
            }
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            $.post(prefix + "/fund", {ids: ids.join(), requestId: requestId}, function (result) {

                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("操作成功！")
                    refresh();
                } else {
                    $.modal.msgError(result.msg);
                }

            });

        }

        function viewFund(requestId) {
            var options = {
                title: '请款',
                url: ctx + "work/fund/look/" + requestId,
                btn: false
            };
            $.modal.openOptions(options);

        }

        //设置客户
        function setCustomer() {

            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录!");
                return;
            }
            layer.prompt({title: '输入客户名称，并确认', formType: 0}, function (text, index) {
                layer.close(index);


                $.modal.confirm("确认要设置选中的" + ids.length + "条数据吗?", function () {

                    $.post(prefix + "/setcustomer", {ids: ids.join(), customer: text}, function (result) {

                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess("操作成功！")
                            refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }

                    });
                });
            });
        }
//刊登提示
        function publishcheck() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录刊登");
                return ;
            }
            $('#myModal6').modal("show");
        }
        //刊登
        function publish() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录刊登");
                return ;
            }




                $.modal.confirm("确认要批量刊登选中的" + ids.length + "条数据吗?", function () {

                    $.post(prefix + "/publish", {ids: ids.join(), publishLink: $('#publishLink').val(),publishDate: $('#publishDate').val()}, function (result) {

                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess("操作成功！")
                            refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }
                        $('#publishLink').val('')
                        $('#publishDate').val('')
                        $('#myModal6').modal("hide");
                    });
                });

        }

        //刊登
        function publish2() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录刊登");
                return;
            }

            $.modal.confirm("确认要批量刊登选中的" + ids.length + "条数据吗?", function () {

                $.post(prefix + "/publish", {ids: ids.join()}, function (result) {

                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功！")
                        refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }

                });
            });

        }

        //批量拒稿
        function reject() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录拒稿");
                return;
            }
            $.modal.confirm("确认要批量拒稿选中的" + ids.length + "条数据吗?", function () {

                $.post(prefix + "/reject", {ids: ids.join()}, function (result) {

                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功！")
                        refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }

                });
            });

        }

        //批量处理process
        function process() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');
            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录处理");
                return;
            }
            $.modal.confirm("确认要批量处理选中的" + ids.length + "条数据吗?", function () {

                $.post(prefix + "/process", {ids: ids.join()}, function (result) {

                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功！")
                        refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }

                });
            });
        }

        //取消处理
        function undo() {
            var ids = arr.length > 0 ? arr : $.table.selectColumns('paperId');

            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录处理");
                return;
            }
            $.modal.confirm("确认要批量取消处理选中的" + ids.length + "条数据吗?", function () {

                $.post(prefix + "/undo", {ids: ids.join()}, function (result) {

                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功！")
                        refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }

                });
            });
        }

        function refresh() {
            if (arr.length > 0)
                arr = [];
            else
                $.table.refresh();
        }

        var paperType = ["", "net",
            "wb",
            "wx",
            "plane",
            "app",
            "flow"
        ];

        function viewMedia(tp, mediaId) {

            var url = ctx + "work/" + paperType[tp] + "/edit/" + mediaId;


            var options = {
                title: '查看媒体',
                url: url,
                btn: false
            };
            $.modal.openOptions(options);
        }
    </script>
    <!-- 导入区域 -->
    <script id="importTpl" type="text/template">
        <form enctype="multipart/form-data" class="mt20 mb10">
            <div class="col-xs-offset-1">
                <input type="file" id="file" name="file"/>
                <div class="mt10 pt5">
                    <!--<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据-->
                    &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                        class="fa fa-file-excel-o"></i> 下载普通稿件模板</a>
                    <a onclick="$.table.importTemplate(2)" class="btn btn-default btn-xs"><i
                            class="fa fa-file-excel-o"></i> 下载项目稿件模板</a>
                </div>
                <font color="red" class="pull-left mt10">
                    提示：仅允许导入“xls”或“xlsx”格式文件！
                </font>
            </div>
        </form>
    </script>
</body>
</html>